package nowcoder;
/**
 * 扑克牌大小
 * 链接：https://www.nowcoder.com/practice/0a92c75f5d6b4db28fcfa3e65e5c9b3f?tpId=49&&tqId=29277&rp=1&ru=/activity/oj&qru=/ta/2016test/question-ranking
 */
import java.util.*;
public class Day16_2 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String str = input.nextLine();
        // 分割成两副牌
        String[] s = str.split("-");
        String[] s1 = s[0].split(" ");
        String[] s2 = s[1].split(" ");
        //将字符串牌转化为数字牌
        int[] nums1 = strArrToNumArr(s1);
        int[] nums2 = strArrToNumArr(s2);

        //先确定是否为炸
        boolean s1IsZha = nums1.length == 4 || (nums1.length == 2 && nums1[0] == 50);
        boolean s2IsZha = nums2.length == 4 || (nums2.length == 2 && nums2[0] == 50);
        if(s1IsZha && !s2IsZha){
            System.out.println(s[0]);
            return;
        }else if(!s1IsZha && s2IsZha){
            System.out.println(s[1]);
            return;
        }else if(s1IsZha && s2IsZha && nums1.length != nums2.length){
            if(nums1.length == 2){
                //第一手是王炸
                System.out.println(s[0]);
            }else{
                //第二手是王炸
                System.out.println(s[1]);
            }
            return;
        }

        //再通过牌的个数确定牌的类型
        if(nums1.length != nums2.length){
            System.out.println("ERROR");
        }else{
            if(nums1[0] > nums2[0]){
                System.out.println(s[0]);
            }else{
                System.out.println(s[1]);
            }
        }
    }

    //将字符串牌转化为数字牌
    private static int[] strArrToNumArr(String[] s) {
        // 3 4 5 6 7 8 9 10 J Q K A 2 joker JOKER
        int[] nums = new int[s.length];
        for (int i = 0; i < s.length; i++) {
            if(s[i].equals("J")){
                nums[i] = 11;
            }else if(s[i].equals("Q")){
                nums[i] = 12;
            }else if(s[i].equals("K")){
                nums[i] = 13;
            }else if(s[i].equals("A")){
                nums[i] = 14;
            }else if(s[i].equals("2")){
                nums[i] = 15;
            }else if(s[i].equals("joker")){
                nums[i] = 50;
            }else if(s[i].equals("JOKER")){
                nums[i] = 100;
            }else{
                nums[i] = Integer.parseInt(s[i]);
            }
        }
        return nums;
    }
}
